<!--
 * @FilePath: \plugWeb\src\components\Test.vue
 * @Version: 2.0
 * @LastEditors: lhl
 * @LastEditTime: 2021-11-03 09:40:26
 * @Description: 
-->
<template>
  <div class="test"
       @mouseup="mouseup"
       @mousemove="mousemove">
    <div class="time-line">
      <div class="time-drag">
        <div class="button"
             :style="{ left: buttonLeft + 'px' }"
             @mousedown="mousedown"></div>
      </div>
      <div class="time-element"
           v-for="item in timeList"
           :key="item"
           :style="{ width: `${100 / timeList.length}%`, height: '100%' }">
        {{ item }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      timeList: [1997, 1998, 1999, 2000, 2001, 2002],
      buttonLeft: 0,
      downPlace: 0,
      lastbuttonLeft: 0,
      down: false
    }
  },
  methods: {
    mousedown (e) {
      this.down = true
      this.lastbuttonLeft = this.buttonLeft
      this.downPlace = e.pageX
    },
    mousemove (e) {
      if (this.down) {
        this.buttonLeft = this.lastbuttonLeft + e.pageX - this.downPlace
      }
    },
    mouseup (e) {
      this.down = false
      this.downPlace = 0
    }
  }
}
</script>

<style lang="less" scoped>
.test {
  height: 100%;
  width: 100%;
  .time-line {
    position: relative;
    height: 10%;
    width: 100%;
    .time-element {
      float: left;
    }
    .time-drag {
      position: absolute;
      width: 100%;
      height: 10%;
      background: black;
      bottom: 0;
      .button {
        position: absolute;
        top: 0;
        height: 400%;
        width: 100px;
        background: brown;
        transform: translateY(-30%);
      }
    }
  }
}
</style>
